﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.DeleteStoreRequest
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.Collections;
using System.IO;

namespace Microsoft.InfoCards
{
  internal class DeleteStoreRequest : UIAgentRequest
  {
    public DeleteStoreRequest(
      IntPtr rpcHandle,
      Stream inArgs,
      Stream outArgs,
      ClientUIRequest parentRequest)
      : base(rpcHandle, inArgs, outArgs, parentRequest)
    {
    }

    protected override void OnMarshalInArgs()
    {
    }

    protected override void OnProcess()
    {
      StoreConnection connection = StoreConnection.GetConnection();
      try
      {
        connection.BeginTransaction();
        try
        {
          QueryParameter deleteStoreTypeQuery = DataSource.CreateDeleteStoreTypeQuery();
          ICollection collection = (ICollection) connection.Query(QueryDetails.Identifiers, connection.LocalDataSource, deleteStoreTypeQuery);
          if (collection != null && collection.Count > 0)
          {
            foreach (DataRow row in (IEnumerable) collection)
              connection.Delete(row);
          }
          connection.CommitTransaction();
          AuditLog.AuditStoreDeletion();
        }
        catch
        {
          connection.RollbackTransaction();
          throw;
        }
      }
      finally
      {
        connection.Close();
      }
    }

    protected override void OnMarshalOutArgs()
    {
    }
  }
}
